package resources;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import rice.p2p.commonapi.NodeHandle;
import rice.pastry.Id;


public class LiveNodeHandleTest {
	private NodeHandle nh;
	private Id nodeId;

	@Before
	public void createLiveNodeHandle() {
		nodeId = Id.build("0x1234");
		nh = new LiveNodeHandle(nodeId);
	}
	
	@Test
	public void aLiveNodeHandleHasTheIdItWasAttributed() {
		assertEquals(nodeId, nh.getId());
	}
	
	@SuppressWarnings("deprecation")
	@Test
	public void aLiveNodeHandleIsAlive() {
		assertTrue(nh.isAlive());
		assertTrue(nh.checkLiveness());
	}
	
	@Test
	public void aLiveNodeHandleIsEqualToAnotherLiveNodeHandleWithSameId() {
		assertEquals(nh, new LiveNodeHandle(nodeId));
	}

	
	@Test
	public void aLiveNodeHandleIsNotEqualToAnotherLiveNodeHandleWithADifferentId() {
		Id anotherId = Id.build("0xababbaba");
		assertFalse(nh.equals(new LiveNodeHandle(anotherId)));
	}
}
